import Joi from 'joi';

// 创建管理员用户字段校验
export const createAdminUserVerify = Joi.object({
	avatar: Joi.string().uri(),
	nickname: Joi.string().min(1).required(),
	username: Joi.string().min(1).required(),
	password: Joi.string().min(8).required(),
	permission: Joi.string().min(1).required(),
});

// 校验是否为有效链接
export const isUrl = (url: string): boolean => {
	const pattern = /^https?:\/\/[^\s/$.?#].[^\s]*$/;
	return pattern.test(url);
};

// 仅包含 name、description 字段的校验
export const nameDescVerify = Joi.object({
	name: Joi.string().min(2).required(),
	description: Joi.string().min(2).required(),
});

// 创建资源字段校验
export const createResourceVerify = Joi.object({
	icon: Joi.string().uri().required(),
	name: Joi.string().min(2).required(),
	description: Joi.string().min(2).required(),
	url: Joi.string().uri().required(),
	details: Joi.string().min(2).required(),
	mainCategoryId: Joi.string().min(2).required(),
	subCategoryId: Joi.string().min(2).required(),
	isRecommend: Joi.boolean().required(),
});
